package jh.com.jhappbf.platenumber;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import androidx.fragment.app.Fragment;
import jh.com.jhappbf.R;

/**
 * @author Administrator
 */
public class CharacterFragment extends Fragment {

    private GridView mGridView;
    private TextView mTxt;
    private List<String> mData;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.platenum_digit, null);
        InitView(view);
        return view;
    }

    private void InitView(View v) {
        mData = new ArrayList<>();
        mGridView = v.findViewById(R.id.digit_gridview);
        mTxt = getActivity().findViewById(R.id.platenum_content_txt);
        mData = Arrays.asList(getResources().getStringArray(R.array.character));
        ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
                R.layout.grdview_item, mData);
        mGridView.setAdapter(adapter);

        mGridView.setOnItemClickListener((parent, view, position, id) -> {
            String value = mTxt.getText().toString();
            if (value.length() == 7) {
                Toast.makeText(getActivity(), "超出了车号的最大位数!", Toast.LENGTH_LONG).show();
                return;
            }
            mTxt.append(mData.get(position));
        });
    }
}
